#include "TcpServer.hpp"
#include <iostream>

using std::cout;
using std::endl;

void onConnection(ln::TcpConnectionPtr conn){
    cout << "== version : Reactor V3 ==" << endl;
    cout << conn->toString() << " has connected successfully!" << endl;
}

void onMessage(ln::TcpConnectionPtr conn){
    //接收消息
    string msg = conn->receive();

    //一些业务逻辑的处理
    
    //回显
    conn->send(msg);
}

void onClose(ln::TcpConnectionPtr conn){
    cout << "== version : Reactor V3 ==" << endl;
    cout << conn->toString() << "has closed" << endl;
}

int main()
{
    ln::TcpServer server(8000);
    printf("server start listening...\n");

    //设置三个回调函数
    server.setAllCallbacks(onConnection,onMessage,onClose);

    //服务器开启事件循环
    server.start();

    return 0;
}

